<div class="tot_login">
<div class="login">
<div class="tot_mer">
  <h2> Request Report</h2>

<?php if( $success_message ):?>
	<div style="color:green;margin-bottom:10px;"><?php echo $success_message; ?></div>
<?php endif;?>

<?php if( $error_message ):?>
	<div style="color:red;margin-bottom:10px;"><?php echo $error_message; ?></div>
<?php endif;?>

<div class="login_form">
  <div class="form1">
    <form method="POST">
        <div class="my_field">
            <p>
                <span class="a">Merchant</span>:
                <?php echo form_dropdown('merchant_id', $merchants, $form['merchant_id'], 'id="search"');?>
            </p>    
                <?php echo form_error('merchant_id', '<div class="error er">', '</div>'); ?>
        </div>

        <div class="my_field">
            <p>
                <span class="a">Report </span>:
                <?php echo form_dropdown('report_type', array('' => 'Select Report')+$reports, $form['report_type'], 'id="search"');?>
            </p>    
                <?php echo form_error('report_type', '<div class="error er">', '</div>'); ?>
        
        </div>

        <div class="my_field">
            <p>
                <span class="a">Interval Type</span>:
                <select  name="interval_type" id="interval_type"  onchange="set_date_as_of(this,'start_date','end_date');">
                  <?php echo date_range_options($form['interval_type']);?>
                </select>
            </p>    
            <?php echo form_error('interval_type', '<div class="error er">', '</div>'); ?>
            
        </div>

        <div class="my_field">
            <p>
                <span class="a">Start Date:</span>:
                <input type="text" name="start_date" id="start_date"  value="<?php echo set_value('start_date',$form['start_date']);?>" />
            </p>
                <?php echo form_error('start_date', '<div class="error er">', '</div>'); ?>
            
        </div>

        <div class="my_field">
            <p>
                <span class="a">End Date</span>:
                <input type="text" name="end_date" id="end_date"  value="<?php echo set_value('end_date',$form['end_date']);?>" />
            </p>    
            <?php echo form_error('end_date', '<div class="error er">', '</div>'); ?>
        </div>

         <div class="my_field">
            <p>
                <span class="a">Add or Replace</span>:
                <span style="color:#000000;">
                <input type="radio" name="add_replace" id="add_replace"  value="add" <?php echo set_radio('add_replace', 'add', ($form['add_replace'] == 'add')); ?> /> Add &nbsp;&nbsp;   
                <input type="radio" name="add_replace" id="add_replace"  value="replace" <?php echo set_radio('add_replace', 'replace', ($form['add_replace'] == 'replace')); ?> /> Replace 
            </p>    
                <?php echo form_error('add_replace', '<div class="error er">', '</div>'); ?>            
        </div>
    	  <div class="my_field">
    		  <button type="submit" class="re_next2">Submit</button>
        </div>   
    	
    </form>
  </div>
  </div>
</div>
</div>
</div>

<script>
$(function() {


  var startDateTextBox = $('#start_date');
  var endDateTextBox = $('#end_date');

$.timepicker.datetimeRange(
  startDateTextBox,
  endDateTextBox,
  {
    minInterval: (1000*60*60), // 1hr
    dateFormat: 'yy-mm-dd', 
    timeFormat: 'HH:mm',
    start: {}, // start picker options
    end: {} // end picker options         
  }
);
startDateTextBox.datetimepicker('setDate', '-30d');
endDateTextBox.datetimepicker('setDate', 'Now');

/*
$("#start_date,#end_date").bind('change', function(){
  $('#interval_type').val('custom');
});
*/

  });


function set_date_as_of(e,target_input,target_input2){
    
    target_input2 = target_input2?target_input2:false;

	if($(e).find(":selected").val() == 'custom')
    {
     return false;   
    }
    else if(($(e).find(":selected").val()).indexOf("since") ===0 && !target_input2 ){
      $("#"+target_input).val("");
      return false;  
    }
    
    if(target_input2){
        var dat1 = $(e).find(':selected').attr("lowdateval");
        var dat2 = $(e).find(':selected').attr("highdateval");
    
        $("#"+target_input).val(dat1);
        $("#"+target_input2).val(dat2);

        $("#"+target_input).datepicker("update", dat1);
        $("#"+target_input2).datepicker("update", dat2);
    }
    else
    {
        var dat = $(e).find(':selected').attr("highdateval");
    
        //$("#"+target_input).val(dat);
        $("#"+target_input).datepicker("update", dat);

       
    }
           
}

  </script>
